package Particles 
{
	import Native.NativeSprite;
	
	import flash.display.MovieClip;
	import flash.display.Sprite;

    public class ParticleLayer 
	{
        public var parent:Sprite;
		public var toSyncRemoved:Boolean=false;
        public var particles:Array;

        public function ParticleLayer()
		{
            particles = new Array();
            super();
        }
        public function update():void
		{
			for each(var particle:Particle in particles)
			{
				particle.update();
			}
			if(toSyncRemoved)
			{
				syncRemoved();
				toSyncRemoved=false;
			}
        }
		private function syncRemoved():void
		{
			particles = particles.filter(function (particle:Particle, index:int, arr:Array):Boolean{
				return !particle.removed;
			});
		}
        public function addParticle(particle:Particle):void
		{
			particle.update();
            parent.addChild(particle.obj);
            particles.push(particle);
        }
        public function remove():void
		{
            var particle:Particle;
            for each (particle in particles) 
			{
				particle.remove();
            }
            particles = new Array();
        }

    }
}